/* Replication Code for "What Do We Measure When We Measure Affective Polarization?" */ 
/* Druckman and Levendusky, Accepted for Publication, POQ */ 
/* This Version: September 2018 */ 

/* Read in the Data & Set the Directory */ 
log using poq_replication.log 
use "poq_replication_data.dta", clear 

/************************************************/
/* Construct Measures of Affective Polarization */
/************************************************/
 
/* Feeling Thermometers */ 
gen thermout = .
replace thermout = reptherm if partyid_wave2 < 4
replace thermout = demtherm if partyid_wave2 > 4

gen thermin = . 
replace thermin = demtherm if partyid_wave2 < 4 
replace thermin = reptherm if partyid_wave2 > 4 

gen therm_diff = thermin - thermout 


/* Trait Ratings */ 
alpha reppat repintel rephonest repopen repgener
alpha rephyp repself repmean
alpha dempat demintel demhonest demopen demgener
alpha demhyp demself demmean

corr reppat repintel rephonest repopen repgener
corr rephyp repself repmean
corr dempat demintel demhonest demopen demgener
corr demhyp demself demmean

egen repgood = rowmean(reppat repintel rephonest repopen repgener)
egen repbad = rowmean(rephyp repself repmean)
egen repall = rowmean(reppat repintel rephonest repopen repgener rephyp repself repmean) 

egen demgood = rowmean(dempat demintel demhonest demopen demgener)
egen dembad = rowmean(demhyp demself demmean)
egen demall = rowmean(dempat demintel demhonest demopen demgener demhyp demself demmean) 

gen same_good = . 
replace same_good = demgood if partyid_wave2 < 4 
replace same_good = repgood if partyid_wave2 > 4 

gen other_good = . 
replace other_good = demgood if partyid_wave2 > 4 
replace other_good = repgood if partyid_wave2 < 4 

gen same_bad = . 
replace same_bad = dembad if partyid_wave2 < 4 
replace same_bad = repbad if partyid_wave2 > 4 

gen other_bad = . 
replace other_bad = dembad if partyid_wave2 > 4 
replace other_bad = repbad if partyid_wave2 < 4 

gen same_all = . 
replace same_all = demall if partyid_wave2 < 4 
replace same_all = repall if partyid_wave2 > 4 

gen other_all = . 
replace other_all = demall if partyid_wave2 > 4 
replace other_all = repall if partyid_wave2 < 4 

gen gooddiff = .
gen repdemgood = repgood-demgood 
gen demrepgood = demgood-repgood
replace gooddiff = repdemgood if partyid_wave2 < 4 
replace gooddiff = demrepgood if partyid_wave2 > 4

gen baddiff = .
gen repdembad = repbad-dembad 
gen demrepbad = dembad-repbad
replace baddiff = repdembad if partyid_wave2 < 4 
replace baddiff = demrepbad if partyid_wave2 > 4 

/* In-Party/Out-Party Favorability */ 
gen out_favorability = other_good - other_bad 
gen in_favorability = same_good - same_bad 


/* Social Distance Items: Scale into One */ 
/* Higher values mean more social distance */ 
gen sd1 = (-1*comfort_friends) + 5 
gen sd2 = (-1*comfort_neighbor) + 5 
alpha sd1 sd2 comfort_marriage 
egen soc_dist = rmean(sd1 sd2 comfort_marriage) 
 
/* Party Trust */ 
gen same_trust = . 
replace same_trust = demtrust if partyid_wave2 < 4 
replace same_trust = reptrust if partyid_wave2 > 4 

gen other_trust = . 
replace other_trust = reptrust if partyid_wave2 < 4 
replace other_trust = demtrust if partyid_wave2 > 4 


/********************************************/
/* Correlation Matrix of Measures (Table 1) */
/********************************************/
/* ssc install polychoric */ 
polychoric thermout out_favorability other_trust soc_dist 
return list /* this gives you the N used for calcuation */ 

/* What's the correlation for the differenced measures of affective polarization? */ 
gen trait_diff = in_favorability - out_favorability 
gen trust_diff = same_trust - other_trust 

polychoric therm_diff trait_diff trust_diff soc_dist 
return list
/* If anything, even stronger correlations */ 


/*********************************************************/
/* Differences Across Experimental Conditions? (Table 2) */
/*********************************************************/
 
/* Feeling Thermometers */ 
reg thermout i.condition 
outreg2 using exp_efffects.doc, dec(2) 
test 2.condition == 3.condition 

/* Trait Ratings */ 
reg out_favorability i.condition 
outreg2 using exp_efffects.doc, dec(2) append 
test 2.condition == 3.condition  

/* Trust in Parties */ 
reg other_trust i.condition 
outreg2 using exp_efffects.doc, dec(2) append 
test 2.condition == 3.condition 

/***************************************/
/* Correlation by Condition (Appendix) */
/***************************************/

forval i=1/3{
	polychoric thermout out_favorability other_trust soc_dist if condition ==`i'  
	return list
}

forval i=1/3{
	polychoric therm_diff trait_diff trust_diff soc_dist if condition ==`i' 
	return list 
}

************************************
** Convergent Validity (Appendix) **
************************************

/* Partisan Social Identity (combined across Huddy et al. items) */ 
alpha party_soc_iden1 party_soc_iden2 party_soc_iden3 party_soc_iden4 /* alpha = 0.87 */ 
egen party_soc_iden = rmean(party_soc_iden1 party_soc_iden2 party_soc_iden3 party_soc_iden4)  
cor party_soc_iden party_import 
/* no surprise, these two are highly inter-related (r=0.81) */ 

/* Generate Postive/Negative Sentiments toward the parties */ 
/* Following Lavine edt al. 2012, 57-60, we code this variable on 0 --> 1 scale, higher values means you have stronger eval */ 
gen dem_pos = . 
replace dem_pos = 0 if demfav1 == 1 
replace dem_pos = 0.25 if demfav1 == 2 & demfav2 == 1
replace dem_pos = 0.50 if demfav1 == 2 & demfav2 == 2 
replace dem_pos = 0.75 if demfav1 == 2 & demfav2 == 3
replace dem_pos = 1 if demfav1 == 2 & demfav2 == 4 

gen rep_pos = . 
replace rep_pos = 0 if repfav1 == 1 
replace rep_pos = 0.25 if repfav1 == 2 & repfav2 == 1
replace rep_pos = 0.50 if repfav1 == 2 & repfav2 == 2 
replace rep_pos = 0.75 if repfav1 == 2 & repfav2 == 3
replace rep_pos = 1 if repfav1 == 2 & repfav2 == 4 

gen dem_neg = . 
replace dem_neg = 0 if demunfav1 == 1 
replace dem_neg = 0.25 if demunfav1 == 2 & demunfav2 == 1
replace dem_neg = 0.50 if demunfav1 == 2 & demunfav2 == 2 
replace dem_neg = 0.75 if demunfav1 == 2 & demunfav2 == 3
replace dem_neg = 1 if demunfav1 == 2 & demunfav2 == 4 

gen rep_neg = . 
replace rep_neg = 0 if repunfav1 == 1 
replace rep_neg = 0.25 if repunfav1 == 2 & repunfav2 == 1
replace rep_neg = 0.50 if repunfav1 == 2 & repunfav2 == 2 
replace rep_neg = 0.75 if repunfav1 == 2 & repunfav2 == 3
replace rep_neg = 1 if repunfav1 == 2 & repunfav2 == 4 

gen same_pos = . 
replace same_pos = dem_pos if partyid_wave2 < 4 
replace same_pos = rep_pos if partyid_wave2 > 4 

gen other_pos = . 
replace other_pos = rep_pos if partyid_wave2 < 4 
replace other_pos = dem_pos if partyid_wave2 > 4 

gen same_neg = . 
replace same_neg = dem_neg if partyid_wave2 < 4 
replace same_neg = rep_neg if partyid_wave2 > 4 

gen other_neg = . 
replace other_neg = rep_neg if partyid_wave2 < 4 
replace other_neg = dem_neg if partyid_wave2 > 4 

/* Calculate univalence */ 
gen univalence = (same_pos + other_neg) -(same_neg + other_pos) 

/* Output regressions for appendix tables */ 
foreach var of varlist thermout out_favorability other_trust soc_dist{
	reg `var' party_soc_iden  
	outreg2 using part_soc_iden.doc, dec(2) 
}

foreach var of varlist thermout out_favorability other_trust soc_dist{
	reg `var' party_import   
	outreg2 using party_import.doc, dec(2) 
}

foreach var of varlist thermout out_favorability other_trust soc_dist{
	reg `var' univalence 
	outreg2 using univalence.doc, dec(2) 
}

foreach var of varlist thermout out_favorability other_trust soc_dist{
	reg `var' neg_part 
	outreg2 using neg_part.doc, dec(2) 
}
 

/**********************************/
/* Identity Importance (Appendix) */
/**********************************/

/* Relative Importance of Identities? */ 
mean amer_import religion_import racial_import gender_import class_import party_import 

log close 
